﻿@if (treemapItems == null)
{
	<Loading></Loading>
}
else
{
	<Treemap @ref=_chart Data="_treeMapData" Config="config" />
}



@code {
	public class TreeMapData
	{
		public string Name { get; set; }
		public List<TreeItemData> children { get; set; }
	}
	public class TreeItemData
	{
		public string name { get; set; }
		public double value { get; set; }
	}

	[Parameter]
	public List<TreeItemData> treemapItems { get; set; }
	[Parameter]
	public int height { get; set; }
	[Parameter]
	public int width { get; set; }
	private TreeMapData _treeMapData=new();
	readonly TreemapConfig config = new TreemapConfig
	{
		ColorField = "name"
	};
	private IChartComponent _chart;
	protected override async void OnParametersSet()
	{
		_treeMapData.Name = "root";
		_treeMapData.children = treemapItems;
		config.Height = height;
		config.Width = width;
		if (_chart != null)
		{
			await _chart.ChangeData(_treeMapData);
		}
		
		base.OnParametersSet();
	}
}
